<template>
	<sc-water-mark ref="wm" :text="waterMarkContent" :subtext="waterMarkSubtext" :showWater="waterMark=='1'">
		<el-main class="nopadding">
			<div id='divId' class="ofddiv"></div>
		</el-main>
	</sc-water-mark>
</template>

<script>
import { parseOfdDocument, renderOfd } from "ofd.js";
import config from "@/config";
import tool from "@/utils/tool";
export default {
	components: {
	},
	data() {
		return {
			extName:this.$route.query.extName,
			attachId:this.$route.query.attachId,
			netDiskId:this.$route.query.netDiskId,
			isNetDisk:this.$route.query.isNetDisk,
			waterMarkContent:'',
			waterMarkSubtext:'',
			waterMark:'0',
			url:'',
		}
	},
	mounted() {
		this.waterMark = this.$TOOL.data.get("WATER_MARK");
		this.waterMarkContent = this.$TOOL.data.get("WATER_MARK_CONTENT");
		this.waterMarkSubtext = this.$TOOL.data.get("WATER_MARK_SUBTEXT");
		if(this.isNetDisk=='true')
		{
			if(config.SM4_PRIVATE_KEY!='')
			{
				this.url = config.API_URL+'/get/file/downNetDiskFile?netDiskId=' + tool.crypto.createParam(this.netDiskId) + "&fileName=" + tool.crypto.createParam(this.attachId);
			}else{
				this.url = config.API_URL+'/get/file/downNetDiskFile?netDiskId=' + this.netDiskId + "&fileName=" + encodeURIComponent(this.attachId);
			}
		}else {
			if(config.SM4_PRIVATE_KEY!='')
			{
				this.url = config.API_URL+'/get/file/getFileDown?attachId=' + tool.crypto.createParam(this.attachId);
			}else{
				this.url = config.API_URL+'/get/file/getFileDown?attachId=' + this.attachId;
			}
		}
		this.getViewOfd();
	},
	methods:{
		getViewOfd(){
			parseOfdDocument({
				// ofd写入文件地址
				// ofd: 数据流,（上传流数据或者接口地址）
				// ofd写入文件地址
				ofd: this.url,//或者在parseOfdDocument上面先调用接口把返回的值传在这里
				success(res) {

					if (res) {
						let screenWidth = 1000 //容器大小
						const divs = renderOfd(screenWidth, res[0])
						let contentDiv = document.getElementById('divId')
						contentDiv.innerHTML = ''
						for (const div of divs) {
							contentDiv.appendChild(div)
						}

					}
				},
				fail(error) {
					console.log(error, 'errror')
				}
			})
		}
	}
}
</script>

<style scoped>
.ofddiv {
	text-align: -webkit-center;
}
</style>
